package com.xiaojiang.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.xiaojiang.domain.Cust;
import com.xiaojiang.factory.BasicFactory;
import com.xiaojiang.service.CustService;

public class addCustServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		
	} 
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		//�ӿڽ���
		CustService service = BasicFactory.getFactory().getInstance(CustService.class);
		//��װ����
		Cust cust = new Cust();
			try {
				BeanUtils.populate(cust,request.getParameterMap());
				//����������
//				String [] str = request.getParameterValues("preference");
//				StringBuffer buff = new StringBuffer();
//				for(String s : str)
//				{
//					buff.append(s+",");
//				}
//				String s = buff.substring(0,buff.length()-1);
				service.addCust(cust);
				//response.sendRedirect(request.getContextPath()+"/listCust.jsp");
				response.sendRedirect(request.getContextPath()+"/servlet/listCust");
			}catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		
			
	}

}
